<!--original copy -->
<h1>Invite Friends original copy</h1>
	<?php
	$type = 'text';
	$senderName = $senderEmail = '';
	$authedUser = $session->read('Auth.User');

	if($authedUser)
	{
		$senderName = $authedUser['username'];
		$senderEmail = $authedUser['email'];
		$type ='hidden';
	}
	?>
	<?php 	
	echo $form->create('Invite',array('action'=>'inviteFriends','id'=>'invite_form'));
	echo $form->input('Sender.name',array('label'=>'Your name','type'=>$type,'value'=>$senderName,'class'=>'required'));
	echo $form->input('Sender.email',array('class'=>'required email','label'=>'Your Email Address','type'=>$type,'value'=>$senderEmail));
	for($i =0; $i<=1; $i++)
	{
		$j= $i;
		$j++;
		if($j==1)
			$classRequired = 'required';
		else
			$classRequired='';
		$classEmail='email';
		echo $form->input('Invite.'.$i.'.name',array('label'=>'Friend #'.$j.' Name:','class'=>$classRequired));
		echo $form->input('Invite.'.$i.'.email',array('label'=>'Friend #'.$j.' Email:','class'=>$classRequired.' '.$classEmail));
	}?>
	
	<div id='add'></div>
	<?php echo $html->link(__('Add More Friend'),'#',array('onclick'=>'return addMoreField()','id'=>'add_link'));?>
	<?php 
	if(!isset($this->data['Invite']['title']))
		$this->data['Invite']['title'] ='';
	if(!isset($this->data['Invite']['body']))
		$this->data['Invite']['body'] ='';

	echo $form->input('InviteTemp.title',array('value'=>$this->data['Invite']['title']));
	echo $form->input('InviteTemp.body',array('value'=>$this->data['Invite']['body'],'type'=>'textarea'));
	echo $form->end(array(__('Send Message'),'class'=>'valid'));
	?>

	<script src="<?php echo $html->url('/cms/js/jquery.template.js')?>" type='text/javascript'></script>
	<?php $this->addScript('<script type="text/javascript" src="'.$html->url('/cms/js/jquery.validate.min.js').'"></script>');?>

	<script type='text/javascript'>
	var fieldTemplate = '<div class="input text"><label for="Invite${i}Name">Friend #${j} Name:</label><input name="data[Invite][${i}][name]" type="text" value="" id="Invite${i}Name" /></div><div class="input text"><label for="Invite${i}Email">Friend #${j} Email:</label><input name="data[Invite][${i}][email]" type="text" value="" id="Invite${i}Email" /></div>';

	var tempObj = new templateCount(<?php echo $i?>);
	function templateCount(index)
	{
		this.count = index;
	}
	var temp =$.template(fieldTemplate);
	function addMoreField()
	{
		if(tempObj.count==9)
			$('#add_link').fadeOut('slow');
		$('#add').append(temp,{'i':tempObj.count,'j':tempObj.count+1});
		tempObj.count++;
		return false ;
	}
	$('.valid').click(function()
	{
		if($('#invite_form').valid()==false)
			return;
	});
	</script>